package cn.corgy.registry.nacos;

import cn.corgy.registry.ServiceRegistry;
import cn.corgy.registry.nacos.utils.NacosUtil;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import lombok.extern.slf4j.Slf4j;

import java.net.InetSocketAddress;

@Slf4j
public class NacosServiceRegistry implements ServiceRegistry {
    @Override
    public void registerService(String rpcServiceName, InetSocketAddress inetSocketAddress) {
        NamingService nacosClient = NacosUtil.getNacosClient();
        try {
            NacosUtil.registerService(nacosClient, rpcServiceName, inetSocketAddress);
        } catch (NacosException e) {
            log.error("服务注册失败:", e);
            e.printStackTrace();
        }
    }
}
